﻿using System;
using System.Collections;

namespace FeedbackNetwork.network
{
    public class Moudle
    {
        protected ArrayList layers = new ArrayList();
        protected Loss loss_function = null;

        public void AddLayer(Layer target)
        {
            this.layers.Add(target);
        }

        public FloatTensor Forward(FloatTensor input)
        {
            for (int i = 0; i < this.layers.Count; i++)
            {
                input = ((Layer)layers[i]).Forward(input);
            }
          
            return input;
        }

        public FloatTensor[] Backward(FloatTensor[] input)
        {
            FloatTensor[] temp = input;

            for(int i = this.layers.Count-1; i>=0; i--)
            {
                temp = ((Layer)this.layers[i]).Backward(temp);
            }
            return temp;
        }

        public void SetLearnRate(float lr)
        {
            foreach (Layer layer in layers)
            {
                layer.SetLearnRate(lr);
            }
        }

        public void SetLossFunction(Loss func)
        {
            this.loss_function = func;
        }

        override
        public String ToString()
        {
            String result = "";
            foreach(Layer layer in this.layers)
            {
                result = result + layer.ToString() + "\n";
            }
            return result;
        }
    }
}
